< previous page page_600 next page >

Page 600
Day 5, Objects, Collections, and Array Processing
Quiz
8694cbadb9b1ef7075903f6f95fc1db2.gif
1. There are two functions available in Visual Basic to determine the class of an object: the TypeOf and TypeName functions.
8694cbadb9b1ef7075903f6f95fc1db2.gif
2. The WithEnd With statements are efficient only when you are working with many properties of a control. When assigning only one or two properties it is better to just code the full statements.
8694cbadb9b1ef7075903f6f95fc1db2.gif
3. All collections share four objects:
8694cbadb9b1ef7075903f6f95fc1db2.gif
Add method
8694cbadb9b1ef7075903f6f95fc1db2.gif
Remove method
8694cbadb9b1ef7075903f6f95fc1db2.gif
Item method
8694cbadb9b1ef7075903f6f95fc1db2.gif
Count property
8694cbadb9b1ef7075903f6f95fc1db2.gif
4. You can create a new instance of a class or an object by declaring it in the Declarations section as follows:
8694cbadb9b1ef7075903f6f95fc1db2.gif
Private myObj as New [object]
8694cbadb9b1ef7075903f6f95fc1db2.gif
The object is created on the first reference in the code.
Exercise
To create an application that places new controls on the form when a command button is clicked, you must place one copy of the control on the form and set its visible property to False and its Index property to 0. This will properly create the control array. Then, every time you must add another copy of the control to the form, load the next element in the array and make it visible. The code for this exercise is shown in Listing A.1.
LISTING A.1. CHAP5EXE.TXTTHE FINISHED CODE FOR THE EXERCISE.

8694cbadb9b1ef7075903f6f95fc1db2.gif
Dim txtTop As Integer
Dim txtLeft As Integer
Dim txtCount As Integer
Dim txtHeight As Integer
Dim txtWidth As Integer

Private Sub Command1_Click()
txtCount = txtCount + 1
Load Text1(txtCount)
Text1(txtCount).Top = txtTop
Text1(txtCount).Left = txtLeft
txtTop = Text1(txtCount).Top + txtHeight + 120

 
< previous page page_600 next page >

If you like this book, buy it!